package com.zh.rent.comm;

import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Interceptor2 implements HandlerInterceptor {
    protected org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler)throws Exception {

        HttpSession session = request.getSession();
        Integer i=null;
               i = (Integer)session.getAttribute("i");
        System.out.println("登录后："+i);
        System.out.println("url:"+request.getRequestURI());
        if(i!=null ) {//已登录
            return true;
        }else {//未登录
            //直接重定向到登录页面
            //response.sendRedirect(request.getContextPath()+"/view/login.html");
            response.sendRedirect("/houtai/login.html");
            return false;
        }
    }

}
